/*
*********************************
	  SF2D Engine
*********************************

	By Julian Williams
	June 11, 2010
**********************************

	Description:

		Camera used to scroll
	through the game's envirnment
***********************************
*/

#include <iostream>
using namespace std;

#include <fstream>


#include "factory.h"





/* Load Particles Files */
bool Factory::Load_List(const string& cfg_location)
{

	cout << "****************************************************************\n";
	cout << "         ********* Setting up List... *********            \n\n";

//Grab Top Level folders names
	if(!Setup_List(folder_list, cfg_location + "category_list.cfg")) 
	{ 
		cout << "[FACTORY] - Setting Up the List has FAILED! \nError Code: 1337lol" << endl; 
		return false; 
	}
	cout << "# Different Folder Types: " << folder_list.size() << endl;

	
	//Loop through and load each Type
	for(int i = 0; i < folder_list.size(); i++)
	{
		cout << "Folder Name: " << folder_list[i] << "\n\n";
		
		string folder_loc = cfg_location + folder_list[i] + "/";

		item_list.clear();
		if(!Setup_List(item_list, folder_loc + "item_list.cfg")) 
		{ 	
			cout << "Setting Up the *List* has FAILED! \n[ERROR]: 1337lol" << endl; 
			return false; 
		}//end ov item setup

		//Loop through the item list and load the individual items
		for(int j = 0; j < item_list.size(); j++)
		{

				if(item_list.size() == 0) {break;}

				cout << "Type Name: " << item_list[j]  << "\n\n";
		
				string item_loc = folder_loc + item_list[j] + "/";
				cout << item_loc << endl;

				//load individual type folders
				if(!Load_TypeIntoList(item_loc))
				{
					cout <<"[FACTORY] - Type - " << item_list[j] << "- failed to load properly.\n";
					//return false;
				}
				
		}//End ov item loop
			
	}//end ov top folder loop
	cout << "****************************************************\n\n";

	return true;
}//EoF




/* Grab a List of names, It Reads a File for 
   a List of names that are the labels of the 
   folders of resources to load
*/   
bool Factory::Setup_List(vector< string > &list, const string& List_loc)
{


	string list_name;
	cout << "Getting List from: " << List_loc << endl;


	//Open up Ammo List file
	ifstream List_file(List_loc.c_str());
    
	//if file isn't open, return false
	if(!List_file.is_open()) 
	{
		cout << "could not open file: " << List_loc.c_str() << endl;
		return false; 
	}

	do 
	{
		//Read in every line
		getline( List_file, list_name);

		if(list_name == "" || list_name =="<none>") { break; }

		list.push_back(list_name);

	} while( !List_file.eof() );

	//Close file
	List_file.close();

	return true;
}//EoF